/**
 * 
 */
package org.statewalker.fsm;

/**
 * Instances of this type are used to notify about various stages of processes.
 * 
 * @author kotelnikov
 */
public interface IFsmProcessListener<S, E> {

    /**
     * Initializes the specified state. This state was not inserted in the
     * process stack yet.
     * 
     * @param process the process owning the state.
     * @param state
     */
    void beginState(FsmProcess<S, E> process, S state);

    /**
     * This method is called to deactivate the specified process state. When
     * this method is called the given state is already removed from the process
     * stack.
     * 
     * @param process the process owning the state
     * @param state the state to deactivate.
     */
    void endState(FsmProcess<S, E> process, S state);

    /**
     * This method is called to notify about a transition between states. When
     * this method is called the previous state is already de-activated (the
     * method {@link #endState(FsmProcess, Object)} is already called for it)
     * and the next state is not activated yet (the method
     * {@link #beginState(FsmProcess, Object)} is not called yet.
     * 
     * @param process the process for which the transition happens
     * @param prev the initial state of the transition; this state could be
     *        <code>null</code> when the process enters in a state.
     * @param event the event activating the transition
     * @param next the target state of the transition; it could be
     *        <code>null</code> for final transition (if the process goes out of
     *        the parent state)
     */
    void onTransition(FsmProcess<S, E> process, S prev, E event, S next);
}
